package cn.kust.serviceverificationcode.controller;


import cn.kust.microtourismcommon.pojo.dto.ResponseResult;
import cn.kust.microtourismcommon.pojo.response.NumberCodeResponse;


import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author WY
 * @data 2022/7/4 21:09
 **/
@RestController
@RequestMapping("/verificationService")
@Slf4j
public class NumberCodeController {

    @GetMapping("/numberCode/{size}")
    public ResponseResult<NumberCodeResponse> numberCode(@PathVariable("size") int size){
        log.debug("size:" + size);
        log.debug("======生成"+size+"位随机数======");
        // Hutool解决方法
//        String s = RandomUtil.randomNumbers(size);
//        System.out.println(s);
        //算法解决
        double mathRandom = (Math.random() * 9 + 1) * (Math.pow(10,size-1));
        System.out.println();
        log.debug(String.valueOf(mathRandom));
        //调用三分api

        //返回数据
        NumberCodeResponse response = new NumberCodeResponse();
        response.setNumberCode((int)mathRandom);

        return ResponseResult.success(response);
    }


}
